﻿using Ducu.BLL.Entity.Component;
using Ducu.GLB.Global;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Global.Core.ExtensionMethod;

namespace Ducu.BLL.Entity
{
    public class Task : BaseEntity
    {
        public virtual Plan Plan { get; set; }
        public virtual DateTime CompleteDate { get; set; }
        public virtual IList<HistoryItem> History { get; set; }
        public virtual Status Status { get; set; }

        public virtual User GetPreviousChatter()
        {
            return History.Where(m => m.Executor.Id != Plan.Vower.Id)
                .OrderByDescending(m => m.CreateTime).FirstOrDefault().Executor;
        }

        /// <summary>
        /// Do Not use it directly but try HistoryItem.Build()/Reply()/Accept()
        /// </summary>
        /// <param name="item"></param>
        public virtual void Add(HistoryItem item)
        {
            History = History ?? new List<HistoryItem>();
            History.Add(item);

            if (item.Status != Status.Empty)
            {
                Status = item.Status;
            }
        }
    }
}
